<?php
declare (strict_types=1);

namespace app\api\controller\v1;

use app\common\model\Advertise as AdvertiseModel;

class Advertise
{
    /**
     * 首页广告位
     */
    public function index()
    {
        $data = AdvertiseModel::where(['type' => 1, 'status' => 1])
            ->field('image,keyword')
            ->withAttr('image', function ($val, $data) {
                return strtolower(config("app.domain_url") . str_replace('\\', '/', $val));
            })
            ->order(['id' => 'asc'])
            ->find();
        return sucessMsg(200, '广告位获取成功', ['data' => $data]);
    }

    /**
     * 历年考卷广告位
     */
    public function years()
    {
        $data = AdvertiseModel::where(['type' => 2, 'status' => 1])
            ->field('image,keyword')
            ->withAttr('image', function ($val, $data) {
                return strtolower(config("app.domain_url") . str_replace('\\', '/', $val));
            })
            ->order(['id' => 'asc'])
            ->find();
        return sucessMsg(200, '广告位获取成功', ['data' => $data]);
    }

    /**
     * 课程推荐广告位
     */
    public function course()
    {
        $data = AdvertiseModel::where(['type' => 3, 'status' => 1])
            ->field('image,keyword')
            ->withAttr('image', function ($val, $data) {
                return strtolower(config("app.domain_url") . str_replace('\\', '/', $val));
            })
            ->order(['id' => 'asc'])
            ->find();
        return sucessMsg(200, '广告位获取成功', ['data' => $data]);
    }

}
